﻿@using X.PagedList;
@using X.PagedList.Mvc;
@using FwProject.Roles.Dto
@model IPagedList<RoleOutputDto>
@{
    ViewBag.Title = "角色管理";
}
@section styles{
    <link href="~/Theme/css/plugins/jsTree/style.min.css" rel="stylesheet" />
}
<style>
    .span1 {
        color: red;
        line-height: 22px;
    }
</style>

<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    <button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_ajax" data-url="@Url.Action("Create")" data-backdrop="static"><i class="fa fa-plus"></i>新增角色</button>
                </div>
            </div>
            <div class="ibox-content">
                <div id="data_list">
                    @{ Html.RenderPartial("IndexPartial", Model);}
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
<div id="modal_del" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated fadeIn">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">删除</h4>
            </div>
            <form action="" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="DeletAjaxCallback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" data-ajax-webapi="true" role="form">
                <div class="modal-body">
                    <p>确定要删除？如果有，请先删除该角色包含的用户。</p>
                </div>
                <div class="modal-footer">
                    <button type="reset" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btn_del_sure" type="submit" class="btn btn-danger" data-loading-text="执行中...">确定</button>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/jsTree/jstree.min.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/Scripts/jquery.treegrid.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $('#modal_ajax').on('show.bs.modal', function (e) {
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this);
                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#modal_del').on('show.bs.modal', function (e) {
                $eclick = $(e.relatedTarget);
                var url = $eclick.data('url');
                if (!!url)
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                $(this).find("form").attr("action", url);
            });
            $('#modal_del').on('hidden.bs.modal', function (e) {
                $(this).find("form").attr("action", "");
            });
        });

        function DeletAjaxCallback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $($eclick).parent().parent().remove();
                $("#modal_del").modal("hide");
            }, successInfo);
        }
    </script>
}